package OldFilesKarthik;

import java.io.*;
import java.net.*;
import java.util.*;

class Car_Riders extends Thread
{
 public int iden;
 public Ride d;
 Random temp= new Random();

 public Car_Riders(String ThreadName, Ride d1, int id)
    {
      iden = id;
      d = d1;
      setName(ThreadName); 
      start();
     }

public void run()
    {
      if (getName().equals("rider")) 
             rider(); 
      if (getName().equals("car")) 
             car(); 
    } 

public void rider()
{
 int i;

 for (i = 1; i <= 15; i++)
   {   
     d.request_to_ride(iden);
     /* this will wait until the ride is over  */
     try{
     sleep(temp.nextInt(3000));
     }
     catch(Exception e){}
   }
}

public void car()
{
    int i;

 for (i = 1; i <= 5; i++)
   {
      d.request_car_boarding(iden); /*car must wait until riders have boarded */
       
       d.request_car_leaving(iden);    /*car must wait until less than two cars are in the part */

       /*to simulate duration of a ride */
       try{
    	     sleep(temp.nextInt(3000));
    	     }
    	     catch(Exception e){}
    	     
      d.request_car_exit(iden);  /* car must wait until all riders exit */

      /* to simulate time to refresh and come back again */
      try{
    	     sleep(temp.nextInt(3000));
    	     }
    	     catch(Exception e){}
   }
}
}



